package com.example.demo.collectionexorection;

import com.example.demo.setstudy.Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @Description CollectionTest2
 * @Author songchuanlong
 * @Date 2025-05-16
 */
public class CollectionTest2 {
    public static void main(String[] args) {
        //1、为集合中批量添加元素 使用工具类Collection
        List<String> name = new ArrayList<>();
        List<Integer> age = new ArrayList<>();
        Collections.addAll(name, "张三", "王五", "李四", "张麻子");
        Collections.addAll(age, 18, 56, 20, 21);
        System.out.println(name);
        System.out.println(age);

        //2、public static void shuffle（List<?>list）：打乱Lis集合中的元素顺序。
        Collections.shuffle(age);
        System.out.println(age);

        //3、public static<T>void sort（List<T>list）：对List集合中的元素进行升序排序。
        System.out.println("========================");
        Collections.sort(age);
        System.out.println(age);
        //4.public static <T> void sort(List<T> list.Comparator<？superT>c)：对List集合中元素
        System.out.println("<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>");
        List<Student> sl = new ArrayList<>();
        sl.add(new Student("王大锤",26,179.6));
        sl.add(new Student("小仙女",26,178.6));
        sl.add(new Student("路人甲",32,177.6));
        sl.add(new Student("文艺少",27,177.6));
//        Collections.sort(sl, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return Double.compare(o1.getHeight(), o2.getHeight());
//            }
//        });
        Collections.sort(sl, (Comparator.comparingDouble(Student::getHeight)));
        System.out.println(sl);
    }
}
